<!DOCTYPE html>
<html lang="en">

	<head>
		<meta charset="UTF-8">
		<meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1,user-scalable=no">
		<meta name="apple-mobile-web-app-capable" content="yes">
		<meta name="apple-mobile-web-app-status-bar-style" content="black">
		<meta name="format-detection" content="telephone=no">
		<title>无忧微贷</title>
		<link rel="stylesheet" type="text/css" href="../css/reset.css">
		<link rel="stylesheet" type="text/css" href="../css/common.css">
		<link rel="stylesheet" type="text/css" href="../css/icomoon/style.css">
		<script type="text/javascript" src="../js/rem.js"></script>
	</head>

	<body>
		<div class="m-password m-common">
			<h3 class="header f-pr">
				<span>忘记密码</span>
				<i class="icon-angle-left f-pa"></i>
			</h3>
			<ul>
				<li>
					<label>手机</label>
					<input type="text" class="mobile" placeholder="请输入手机号码">
					<i class="close-icon f-pa"></i>
				</li>
				<li>
					<label>验证码</label>
					<input type="text" class="code" placeholder="请输入验证码">
					<button class="code-text f-pa">获取验证码</button>
					<!-- <i class="close-icon f-pa"></i> -->
				</li>
			</ul>
			<div class="btn-box">
				<a class="btn">下一步</a>
			</div>
			<p class="tips">如有疑问，请联系客服：<span>0755-22217999</span></p>
		</div>
		<script type="text/javascript" src="../js/md5.min.js"></script>
		<script type="text/javascript" src="../js/zepto.min.js"></script>
		<script type="text/javascript" src="../js/mui.min.js"></script>
		<script type="text/javascript" src="../js/common.js"></script>

		<script type="text/javascript">
			mui.plusReady(function() {

				$('.icon-angle-left').on('tap', function() {
					mui.back();
				});

				function validate() {
					var mobile = $.trim($('.mobile').val()),
						code = $.trim($('.code').val());
					if(mobile == '') {
						mui.toast('请输入手机号码');
						return false;
					}
					if(code == '') {
						mui.toast('请输入验证码');
						return false;
					}
					return true;
				}

				function countdowncode(wait) {
					var $obj = $('.code-text');
					if(wait === 0) {
						$obj.text('获取验证码').removeClass('disable').attr('disable', false);
					} else {
						$obj.text(wait + '秒后重发').addClass('disable').attr('disable', true);
						wait--;
						setTimeout(function() {
							countdowncode(wait);
						}, 1000);
					}
				}

				$('.code-text').on('tap', function() {
					var mobile = $.trim($('.mobile').val());
					if(mobile == '') {
						mui.toast('请输入手机号码');
						return false;
					}
					mui.ajax(base + 'passport/findpassword', {
						type: 'post',
						data: { 'mobile': $.trim($('.mobile').val()) },
						dataType: 'json',
						headers: sign(md5),
						success: function(data) {
							console.log('findpassword:'+JSON.stringify(data));
							if(data.result) {
								countdowncode(data.wait_second);
							} else {
								mui.toast(data.message);
							}
						},
						error: function(data) {
							console.error(data);
						}
					});
				});

				$('.btn').on('tap', function() {
					if(!validate()) {
						return false;
					} else {
						mui.ajax(base + 'passport/verifyfindpassword', {
							type: 'post',
							data: {
								'mobile': $.trim($('.mobile').val()),
								'code': $.trim($('.code').val())
							},
							dataType: 'json',
							headers: sign(md5),
							success: function(data) {
								if(data.result) {
									mui.openWindow({ url: 'resetpassword.html', extras: { sign: data.sign } });
								} else {
									mui.alert('请输入正确的验证码');
								}
							},
							error: function(data) {
								console.info(data.message);
							}
						});
					}
				});
			});
		</script>
	</body>

</html>